<?php
use think\facade\Session;
use think\facade\Db;
/**
 * 检测会员是否登录
 * @return integer 0/管理员ID
 */
function is_api_login()
{
    $user = Session::get('user_auth');
    if (empty($user)) {
        return 0;
    } else {
        return Session::get('user_auth_sign') == data_auth_sign($user) ? $user['user_id'] : 0;
    }
}
/**
 * 阅读量增加
 */
function view_article($tablename,$id)
{
    Db::name($tablename)->where('id',$id)->inc('view')->update();
    return ;
}
/**
 * 获取API用户ID
 * @param string $remark 日志备注
 */
function UserId()
{
    return Session::get('user_auth.user_id');
}
//获取商家ID
function ShopId()
{
    return session('user_auth.shop_id');
}
//获取OpenID
function OpenId()
{
    return session('user_auth.openid');
}
/**
 * 保存前台用户行为
 * @param string $remark 日志备注
 */
function insert_api_log($remark)
{
    if (request()->isMobile()) {
        $m = '1';
    }else{
        $m = '0';
    }
    if (session('?user_auth')) {
        Db::name('user_log')->insert([
            'shop_id'     => Session::get('user_auth.shop_id'),
            'client'     => $m,
            'user_id'     => Session::get('user_auth.user_id'),
            'ip'          => request()->ip(),
            'url'         => request()->url(true),
            'method'      => request()->method(),
            'type'        => request()->type(),
            'param'       => json_encode(request()->param()),
            'remark'      => $remark,
            'create_time' => time(),
        ]);
    }
}
//获取客户表参数
function get_customer_config($field)
{
    $list = \app\user\model\CustomerConfig::where('field',$field)->order('sort_order desc,id desc')->select();
    return $list;
}

//最新消息
function Newmessage()
{
    //查询最后看的一个ID
//    $user = Db::name('user')->where('id', Wechat_userid())->find();
//    //统计最后一个到现在的距离
//    $count = \app\api\model\Finance::where('id','>',$user['last_finance_id'])->count();
//    $message['unread'] = $count;
    return '';
}